import json

import requests

if __name__ == "__main__":
    post_url = 'https://fanyi.baidu.com/sug'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
    }
    data = {
        'kw': 'dog',
    }
    response = requests.post(url=post_url, data=data, headers=headers)
    # 获取响应数据.json()放回的是obj对象
    dic_obj = response.json()

    # json数据持久性存储
    fp = open('./dog.json', 'w', encoding='utf-8')
    json.dump(dic_obj, fp=fp, ensure_ascii=False) # 拿到的数据为中文不能Ascll编码
    print('over')